<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>后台管理</title>

    <script src="__STATIC__/jquery-2.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <link rel="stylesheet" href="__STATIC__/layui/css/layui.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">

    {include file="public/header" /}
    {include file="public/left" /}
    <style>
        .layui-table-cell{
            height: 33px;
        }
    </style>



    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div style="padding: 15px;">


            <fieldset class="layui-elem-field layui-field-title"  style="margin-top: 50px;">
                <legend>用户列表</legend>
            </fieldset>
            <form class="navbar-form form-inline" action="" method="get">
                <div class="sDiv" style="margin-top: 20px;">
                    <div class="sDiv2">
                        <div class="layui-inline">
                        <input style="width: 300px;display: block;" type="text" class="layui-input" name="keyword" placeholder="可搜索用户名" value="{$keyword}">
                        </div>
                        <input class="layui-btn" type="submit" value="搜索">
                    </div>
                </div>
            </form>
			<div style="margin-top:10px;">
            <a class="layui-btn layui-btn-warm" href="{:url('User/add')}">新增用户</a>
                <div class="layui-inline">
                  <label class="layui-form-label">开始日期</label>
                  <div class="layui-input-inline">
                    <input type="text" name="start_date" id="start_date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">结束日期</label>
                  <div class="layui-input-inline">
                    <input type="text" name="end_date" id="end_date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                  </div>
                </div>
            <a class="layui-btn layui-btn" id="export" href="{:url('Data/getPatExcel')}">导出</a>
			</div>
            <table class="layui-hide" id="list"></table>



            <script>

                // 实现方法
                // @param name { String } 需要返回的属性名
                // @param arr { Array } 原始数据
                // @return ret { Array } 返回值
                function getParamValues(name, arr) {
                    var ret = []
                    for (var i = 0, len = arr.length; i < len; i++) {
                        ret.push(arr[i][name])
                    }
                    return ret
                }

                layui.use(['table','layer'], function(){
                    var table = layui.table;

                    table.render({
                        elem: '#list'
						,limits: [10,20,30,40,50,60,70,80,90,100,150,200]
                        ,url: "{:url('User/listjson',['keyword'=>$keyword])}"
                        ,cols: [[
                            {type:'checkbox',width:'3%'}
                            ,{field:'uid', width:'10%', title: 'ID', sort: true}
                            ,{field:'username', width:'15%', title: '用户名'}
                            ,{field:'age', width:'15%', title: '年龄',sort: true}
                            ,{field:'height', width:'10%', title: '身高'}
                            ,{field:'weight', width: '10%', title: '体重' }
                            ,{field:'operation', minWidth: '550', title: '操作',templet: '#operation'}
                        ]]
                        ,page: true,
                        id:'tb'
                    });

                    $('#export').click(function (e) {
                        e.preventDefault();
                        var href = $(this).attr('href');
                        var checkStatus = table.checkStatus('tb'); //idTest 即为基础参数 id 对应的值
                        var start_time = $('#start_date').val();
                        var end_time = $('#end_date').val();
                        console.log(checkStatus.data) //获取选中行的数据
                        console.log(checkStatus.data.length) //获取选中行数量，可作为是否有选中行的条件
                        console.log(checkStatus.isAll ) //表格是否全选
                        $ret = getParamValues('uid',checkStatus.data).join(',');
                        console.log($ret);//获取选中行的数据
                        if(checkStatus.data.length == 0){
                            var layer = layui.layer;
                            layer.msg('你没有选中一项');
                            return false;
                        }

                        location.href = href + '?uids='+$ret+'&start_time='+start_time+'&end_time='+end_time;

                    })




                });
            </script>
            <script type="text/html" id="operation">
                <a class="layui-btn layui-btn-normal" href="{:url('User/detail' )}?{literal}uid={{d.uid}} {/literal}" >详细</a>
                <a class="layui-btn layui-btn-normal" href="{:url('Treat/treatment' )}?{literal}uid={{d.uid}} {/literal}" >起始治疗方案</a>
                <a class="layui-btn layui-btn-normal" href="{:url('Treat/history' )}?{literal}uid={{d.uid}} {/literal}" >数据汇总</a>
                <a class="layui-btn layui-btn-normal" href="{:url('Treat/bshistory' )}?{literal}uid={{d.uid}} {/literal}" >血糖记录</a>
                <a class="layui-btn layui-btn-danger delbtn"  onclick=" return confirm('你真的要删除这个用户吗')" href="{:url('User/delete' )}?{literal}uid={{d.uid}} {/literal}" >删除</a>
            </script>

        </div>
    </div>


</div>

<script>

    //JavaScript代码区域
    layui.use('element', function(){
        var element = layui.element;

    });
    $('#logout').click(function (e) {
        e.preventDefault();
        layui.use('layer', function(){
            var layer = layui.layer;

            layer.confirm('你真的要退出吗？',['yes','no'],function () {
                location.href="{:url('login/logout')}";
            },function () {
                
            })
        });
    })

    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //常规用法
        laydate.render({
            elem: '#start_date'
            ,max: 0 //7天后
        });
        laydate.render({
            elem: '#end_date'
            ,max: 0 //7天后
        });
    });




</script>

</body>
</html>